package com.tang.model.itrerator;

import java.util.Collections;
import java.util.List;

/**
 * @Author tangyuan2meicloud.com
 * @DATE 2021/9/3 21:37
 * @Desc
 * @Remarks
 */
public class TYIteratorImpl<T> implements TYIterator {

    private List<T> list;
    private int cursor;

    public TYIteratorImpl(List<T> list) {
        if (list == null) {
            list = Collections.emptyList();
        }
        this.list = list;
    }

    @Override
    public T next() {
        return list.get(cursor++);
    }

    @Override
    public boolean hasNext() {
        if (cursor < list.size()) {
            return true;
        }
        return false;
    }
}
